package cn.com.zero.manager.auth.service.impl;

import cn.com.zero.base.exception.ErrorCodeException;
import cn.com.zero.base.service.BaseService;
import cn.com.zero.manager.auth.mapper.IManageLockedMapper;
import cn.com.zero.manager.auth.po.ManagerPO;
import cn.com.zero.manager.auth.service.IManageLockedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * @author guoxin
 * @version 1.0.0
 * @Description
 * @date 2023/3/1 17:10
 */
@Service
public class ManageLockedService extends BaseService implements IManageLockedService {

    /**
     * 被锁定管理员管理mapper
     */
    private IManageLockedMapper manageLockedMapper;

    /**
     * 查询被锁定的管理员列表
     *
     * @return
     */
    @Override
    public List<ManagerPO> queryList() {
        return manageLockedMapper.queryList();
    }

    /**
     * 解锁管理员
     *
     * @param userId    用户名
     */
    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void unlockAdmin(String userId) {
        ManagerPO managerPO = manageLockedMapper.queryAdmin(userId);
        if(Objects.isNull(managerPO)){
            logger.error("用户名{}不存在", userId);
            throw new ErrorCodeException(-114514L);
        }
        manageLockedMapper.unlockAdmin(userId);
    }

    @Autowired
    public void setManageLockedMapper(IManageLockedMapper manageLockedMapper) {
        this.manageLockedMapper = manageLockedMapper;
    }
}
